<?php

namespace app\common\model;

use think\Model;

/**
 * 会员模型
 */
class WashingRecord extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';
    // 追加属性
    protected $append = [
        'url',
    ];

    public static function get_info($username, $sid)
    {
        //判断用户是否预约
        $info = \app\common\model\WashingRecord::where(['nickname' => $username, 'sid' => $sid,'states'=>1])->find();
        if(!empty($info)){
            if($info['into_states']==1&&$info['leave_states']==0)
            {
                return 4;
            }
            return "2";
        }

        //判断该用户之前是否被锁定 三次未登记离开浴室为锁定
        $count  = \app\common\model\WashingRecord::where(['nickname' => $username, 'sid' => $sid,'into_states'=>1,'leave_states'=>0])->count();
        if($count==3){
            $list = \app\common\model\WashingRecord::where(['nickname' => $username, 'sid' => $sid,'into_states'=>1,'leave_states'=>0])->select();
            // foreach ($list as $key => $value) {
                $where['id'] = $list[0]['id'];
                $row = \app\common\model\WashingRecord::where($where)->find();
                //处理锁定状态
                $params['locked']=3;
                $row->save($params);
            // }
            return "3";
        }


        //成功的情况返回1
        return "1";



    }

}
